
import torch
import numpy as np
import random
import os

def gen_golden_data_reflection_pad1d():
    # 创建专属目录
    input_dir = "./input"
    output_dir = "./output"
    os.makedirs(input_dir, exist_ok=True)
    os.makedirs(output_dir, exist_ok=True)
    
    # 固定配置
    input_shape = (8, 2, 1024)  # N=8, C=2, W=1024
    input_dtype = torch.float32
    input_range = (-3.0, 3.0)
    pad_left = random.randint(1, 1024)
    pad_right = random.randint(1, 1024)
    paddings = (pad_left, pad_right)  # (左填充, 右填充)
    
    # 生成随机输入
    input_x = torch.rand(*input_shape, dtype=input_dtype) * (input_range[1] - input_range[0]) + input_range[0]
    
    pad_layer = torch.nn.ReflectionPad1d(paddings)  # 实例化反射填充层
    golden = pad_layer(input_x)  # 调用forward方法
    
    # 保存数据
    input_x_np = input_x.cpu().numpy()
    paddings_np = np.array(paddings, dtype=np.int32)
    golden_np = golden.cpu().numpy()
    
    input_x_np.tofile(os.path.join(input_dir, "input_x.bin"))
    paddings_np.tofile(os.path.join(input_dir, "paddings.bin"))
    golden_np.tofile(os.path.join(output_dir, "golden.bin"))
    
    # 打印信息
    print(f"生成成功！输入形状: {input_shape}, 输出形状: {golden.shape}")
    print(f"填充参数: {paddings}")

if __name__ == "__main__":
    gen_golden_data_reflection_pad1d()